<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<%@ page contentType="text/html; charset=utf-8"%>
	<%@ include file="/commons/taglibs.jsp"%>
	<head>
		<%@ include file="/commons/css_js_head.jsp"%>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>添加角色</title>
		<script type="text/javascript">
//复写Url
doSaveUrl = "${ctx }/permission/efRoleAction!doSave.ts";
doReturnUrl = "${ctx }/permission/efRoleAction!doList.ts";

//保存
function doSave() {
	var _form = document.forms[0];
	if (doSaveUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}

	_form.action = doSaveUrl;
}

//校验数据
$(document).ready(function(){
	
	$.formValidator.initConfig({formid:"form1",alertmessage:true,onerror:function(msg){alert(msg)},onsuccess:function(){doSave();}});
	
	$("#efRole_roleName").formValidator().inputValidator({min:1,max:16,onerror:"请输入角色名称，且只能在1-16个汉字之间"});
	$("#efRole_roleCode").formValidator().inputValidator({min:1,max:32,onerror:"请输入角色编码，且只能在1-32个字符之间"});

});

//校验角色名称是否存在
function checkRoleNameIsExist() {
	var txtObj = document.getElementById("efRole.roleName");
	var roleNameInfo = document.getElementById("roleNameInfo");
	var roleName = txtObj.value;
	
	if(roleName == ""){
		var innerHtml = "<span class='ts_red'>请输入角色名称！<\/span>";
		getFocus(txtObj,roleNameInfo,innerHtml);
		return false;
	}
    $.ajax({
      type : "post",
      url : "${ctx }/permission/efRoleAction!doCheckRoleNameIsExist.ts",
      cache: false,
      data : "&roleName="+roleName,
      success : function(data){
      
      if( data == "true" )
       {
           var innerHtml = "<span class='ts_red'>该角色名称已经存在，请重新输入！<\/span>";
           roleNameInfo.innerHTML=innerHtml;
           txtObj.value = "";
           txtObj.focus();
           return false;
        }
       else
       {
           var innerHtml = "<span class='ts_green'>验证通过，该角色名称可以使用！<\/span>";
           roleNameInfo.innerHTML=innerHtml;
           return true;
       }
      },
     error: function(){
     	   var innerHtml = "<span class='ts_red'>服务繁忙，请稍后再试！<\/span>";
           roleNameInfo.innerHTML=innerHtml;
           txtObj.value = "";
           return false;
     	}
   });
  	return true;
}

</script>
	</head>
	<body style="overflow-x: hidden">
		<div class="mTitle">
			<span class="hidsearch"></span>
			<b class="bbig">增加角色</b>
			带<b class="fred"> * </b>号为必填项
		</div>

		<!--list -->
		<div class="mainList">
		<s:form action="/easyframe/permission/efRoleAction" id="form1" method="post">
				<table class="addTable">
					<tr>
						<th width="5%">
							<b class="fred">*</b>角色名称：
						</th>
						<td width="40%">
							<s:textfield name="efRole.roleName" id="efRole.roleName" onblur="checkRoleNameIsExist()" theme="simple"></s:textfield>
							<span id="roleNameInfo"></span>
						</td>
					</tr>

					<tr>
						<th width="5%">
							<b class="fred">*</b>角色编码：
						</th>
						<td width="40%">
							<s:textfield id="efRole_roleCode" name="efRole.roleCode" theme="simple"></s:textfield>
						</td>
					</tr>

					<tr>
						<th width="5%">
							<b class="fred">*</b>是否有效：
						</th>
						<td width="40%">
							<select name="efRole.dicRoleIsValid">
								<ef:option groupname="DicRoleIsValid"
									selectedValue="${efRole.dicRoleIsValid}" link="true"></ef:option>
							</select>
						</td>
					</tr>
				</table>
		</div>
		<!--end table -->

		<div class="addToolbar">
			<p>
				<input class="btn" name="btn_confirm" value="确定" type="submit"/>
				<input class="btn" name="btn_return" value="返回" type="button" onclick="doReturn();" ; />
			</p>
		</div>
		</s:form>

</div>

	</body>
</html>